export const isEmptyValue = v => {
  return v === null || v === undefined || v === ''
}

export const formatPercent = v => {
  if (isEmptyValue(v)) {
    return '-%'
  } else {
    return `${(v * 100).toFixed(2)}%`
  }
}

export function keep2(v) {
  if (isEmptyValue(v)) {
    return '-'
  }
  return parseFloat(v).toFixed(2)
}

export function deepClone(arg) {
  const objStr = '[object Object]';
  const arrStr = '[object Array]';
  const type = Object.prototype.toString.call(arg);
  if(typeof arg === 'object') {
    if(type === objStr){
      let res = {};
      for(let key in arg){
        res[key] = deepClone(arg[key])
      }
      return res;
    }
    if(type === arrStr){
      let res = [];
      arg.forEach(item => {
        res.push(deepClone(item))
      })
      return res;
    }
    return arg;
  } else {
    return arg;
  }
}
